import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;


public class AddNewAddrColumn {
public static void main(String[] args) throws IOException {
		
		String srcFileNm 	= args[0];								//입력파일
		
		String targetDs= "DS_NON_SCHE_TX";
		
		File srcFile = new File(srcFileNm);
		File trgFile = new File(srcFileNm+".bak");
		
		FileInputStream inputStream = new FileInputStream(srcFile);
		FileOutputStream outputStream = new FileOutputStream(trgFile);
		
		try{			
			int bytesRead = 0;
			byte[] buffer = new byte[1024];
			while ((bytesRead = inputStream.read(buffer,0,1024)) != -1){
				outputStream.write(buffer,0,bytesRead);
			}
		}catch(Exception e){			
		}
		
		outputStream.close();
		inputStream.close();
		srcFile.delete();
		
		trgFile = new File(srcFileNm);
		srcFile = new File(srcFileNm+".bak");
		
		outputStream = new FileOutputStream(trgFile);
		
		FileReader srcReader;
		try {
			srcReader = new FileReader(srcFile);
			BufferedReader buffer = new BufferedReader(srcReader);
			
			String strReadLine = null;
			
			ArrayList<HashMap<String,String>> rows = new ArrayList<HashMap<String,String>>();
			
			
			String searchKeyword = "Id=\"" + targetDs + "\"";
			boolean findFlag = false;
			
			ArrayList<String> XMLList = new ArrayList<String>();
			while((strReadLine = buffer.readLine()) != null){
				//데이터셋위치 찾기.
				if (findFlag == false){
					if (!strReadLine.contains(searchKeyword)) ;
					else findFlag = true;					 
					outputStream.write(strReadLine.getBytes("UTF-8"),0,strReadLine.getBytes("UTF-8").length);
					outputStream.write('\n');
				}
				else {
					outputStream.write(strReadLine.getBytes("UTF-8"),0,strReadLine.getBytes("UTF-8").length);
					outputStream.write('\n');
				}
			}			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}
